package com.yanqu.road.server.manager.cross.battle;

import com.alibaba.fastjson.annotation.JSONField;
import com.yanqu.road.entity.activity.huashigang.HuaShiGangStrongPoint;
import com.yanqu.road.server.manager.cross.battle.enums.HuaShiGangBuildMode;
import com.yanqu.road.server.manager.cross.battle.enums.eHuaShiGangModeType;

import java.awt.*;

/**
 * @Author wpj
 * @Date 2020/9/28
 */
public class HuaShiGangMode {

    eHuaShiGangModeType modeType;

    HuaShiGangBuildMode modeId;

    public HuaShiGangStrongPoint[][] points;

    public HuaShiGangMode() {

    }

    public HuaShiGangMode(int line, eHuaShiGangModeType modeType) {
        points = new HuaShiGangStrongPoint[line][3];
        this.modeType = modeType;
    }


    /**
     * 在对应坐标上生成据点
     * @param x
     * @param y
     */
    public void setPoint(int x, int y) {
        points[x][y] = new HuaShiGangStrongPoint(x, y);
    }

    /**
     * 在对应坐标上生成据点并添加指向的下一个坐标
     * @param x
     * @param y
     * @param nextPoint
     */
    public void setPointAndAddNextPoint(int x, int y, Point nextPoint) {
        if (points[x][y] == null) {
            points[x][y] = new HuaShiGangStrongPoint(x, y);
        }
        points[x][y].addNextPoint(new Point(nextPoint));
    }

    public HuaShiGangStrongPoint getPoint(int x, int y) {
        for (HuaShiGangStrongPoint[] huaShiGangStrongPoints : points) {
            for (HuaShiGangStrongPoint huaShiGangStrongPoint : huaShiGangStrongPoints) {
                if (huaShiGangStrongPoint != null) {
                    if (huaShiGangStrongPoint.getX() == x && huaShiGangStrongPoint.getY() == y) {
                        return huaShiGangStrongPoint;
                    }
                }

            }
        }
        return null;
    }

    public eHuaShiGangModeType getModeType() {
        return modeType;
    }

    public void setModeType(eHuaShiGangModeType modeType) {
        this.modeType = modeType;
    }

    public HuaShiGangStrongPoint[][] getPoints() {
        return points;
    }

    public void setPoints(HuaShiGangStrongPoint[][] points) {
        this.points = points;
    }

    public HuaShiGangBuildMode getModeId() {
        return modeId;
    }

    public void setModeId(HuaShiGangBuildMode modeId) {
        this.modeId = modeId;
    }

    @JSONField(serialize = false, deserialize = false)
    public int getTopNum() {
        int num = 0;
        for (int i = 0; i <= 2; i++) {
            if (points[i][2] != null) {
                num ++;
            }
        }
        return num;
    }

    @JSONField(serialize = false, deserialize = false)
    public int getBottomNum() {
        int num = 0;
        for (int i = 0; i <= 2; i++) {
            if (points[i][0] != null) {
                num ++;
            }
        }
        return num;
    }
}
